//
//  NWConstant.m
//  ylh-app-primary-ios
//
//  Created by YueWen on 2018/11/28.
//  Copyright © 2018 巨商汇. All rights reserved.
//

#import "QDConstant.h"
#import "RITLKit.h"

@implementation QDConstant


//身份证号是否合法
+ (BOOL) validateIdentityCard: (NSString *)identityCard
{
    BOOL flag;
    if (identityCard.length <= 0) {
        flag = NO;
        return flag;
    }
    NSString *regex2 = @"^(\\d{14}|\\d{17})(\\d|[xX])$";
    NSPredicate *identityCardPredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex2];
    return [identityCardPredicate evaluateWithObject:identityCard];
}


+ (void)showMBHudwithText:(NSString *)text OnView:(UIView *)view DelayTime:(NSInteger)delayTime {
    
    if (!view) { return; }

    MBProgressHUD *showHUD = [MBProgressHUD HUDForView:view];

    if (showHUD) {

        showHUD.label.text = text; return;
//        showHUD.labelText = text;
//        [showHUD hide:true afterDelay:delayTime];
        return;
    }

    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud.mode = MBProgressHUDModeText;
    hud.bezelView.color = [[UIColor blackColor] colorWithAlphaComponent:0.5];
//    hud.color = [[UIColor blackColor] colorWithAlphaComponent:0.5];
    hud.label.text = text;
//    hud.labelText = text;
//        hud.minSize = CGSizeMake(145, 40);
    hud.label.textColor = [UIColor whiteColor];
//    hud.labelColor = [UIColor whiteColor];
    hud.label.font = RITLUtilityFont(RITLFontPingFangSC_Regular, 14);
//    hud.labelFont = RITLUtilityFont(RITLFontPingFangSC_Regular, 14);



    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
        // Do something...
        dispatch_async(dispatch_get_main_queue(), ^{

            [hud hideAnimated:YES afterDelay: delayTime];
//            [hud hide:true afterDelay:delayTime];
        });
    });
}


void ShowMBHudwithText(NSString *text,UIView *onView)
{
    [QDConstant showMBHudwithText:text OnView:onView DelayTime:1];
}

void DismissMBHUD(UIView *onView)
{
    [MBProgressHUD hideHUDForView:onView animated:true];
}


void ShowProgressHUD(UIView *onView,double progress)
{
    RITL_dispatch_main_async_safe(^{

        MBProgressHUD *hud = [MBProgressHUD HUDForView:onView];

        if (hud && hud.mode != MBProgressHUDModeAnnularDeterminate) {
            [hud hideAnimated:false];
//            [hud hide:false];
        }

        if (!hud) {

            hud = [MBProgressHUD showHUDAddedTo:onView animated:true];
            hud.mode = MBProgressHUDModeAnnularDeterminate;
            hud.bezelView.style = MBProgressHUDBackgroundStyleBlur;
//            hud.
        }

        hud.progress = progress;
    });
}


void ShowMBHUD(NSString *text,UIView *onView)
{
    [QDConstant showMBHudwithText:text OnView:onView DelayTime:1];
}

void ShowMBHudwithDelayTime(NSString *text,UIView *onView,NSInteger delayTime) {
    
    [QDConstant showMBHudwithText:text OnView:onView DelayTime:delayTime];
}


void ShowWaitingHUD(UIView *onView)
{
    //如果存在
    MBProgressHUD *hud = [MBProgressHUD HUDForView:onView];
    
    if (hud) {
//        [hud hide:false];
        [hud hideAnimated:false];
    }
    
    hud = [MBProgressHUD showHUDAddedTo:onView animated:true];
    hud.bezelView.style = MBProgressHUDBackgroundStyleBlur;
//    hud.color = [[UIColor blackColor] colorWithAlphaComponent:0.5];
    [hud showAnimated:true];
//    [hud show:true];
}




@end
